using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
using ATCenterProxy.interop;

namespace PowerLanguage.Strategy {
	public class NY_Future_Method_A : SignalObject {
		
		private IOrderMarket m_Buy_Order;
		private IOrderMarket m_Sell_Order;
        private RSI m_RSI;
        private VariableSeries<Double> m_myrsi;
		private ISeries<double> Price { get; set; }
			
		[Input]
        public int Length { get; set; }

        [Input]
        public double L_OverBought { get; set; }
		
		[Input]
        public double S_OverSold { get; set; }
		
		
		public NY_Future_Method_A(object _ctx):base(_ctx){
			Length = 14;
			L_OverBought = 70;
			S_OverSold = 30;
		}
				


        
		
		protected override void Create() {
			// create variable objects, function objects, order objects etc.
			m_Buy_Order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.Buy));
			m_Sell_Order = OrderCreator.MarketNextBar(new SOrderParameters(Contracts.Default, EOrderAction.SellShort));
			
			m_RSI = new RSI(this);
			m_myrsi = new VariableSeries<Double>(this);
			
		}
		protected override void StartCalc() {
			// assign inputs 
			
			Price = Bars.Close;
			m_RSI.price = Price;
			m_RSI.length = Length;
		}
		protected override void CalcBar(){
			// strategy logic 
			m_myrsi.Value = m_RSI[0];
			if (Bars.CurrentBar > 1){
                if (this.CrossesOver(m_myrsi,L_OverBought)){
                    m_Buy_Order.Send();
                }
				if (this.CrossesOver(m_myrsi, S_OverSold))
				{
					m_Sell_Order.Send();
				}
            }
		}
	}
}